#ifndef SENSORDATAPROCESS_H
#define SENSORDATAPROCESS_H

#include <QObject>
#include <QHostAddress>
#include <QMap>

class DatabaseOperation;

class SensorDataProcess : public QObject
{
    Q_OBJECT
public:
    explicit SensorDataProcess(QObject *parent = 0);
    ~SensorDataProcess();
signals:
    void sigEventNotify(QByteArray eventNotify, QString srcIP, quint16 srcPort);
    void sigInfo(QString info); //需要显示的信息
    void sigError(QString errorInfo);
    void sigPacketNodeToServer(QByteArray datagram,QHostAddress GWIP,
             quint16  GWPort,bool isFromTcp); //GWIP是指Sink的IP，此处即为telnet适配器的IP

public slots:
    void slotProcessSensorData(QByteArray packet, QHostAddress srcAddress, quint16 srcPort);
    void beginOfProgram(); //程序开始后的操作

private:
    void updateLastEventDataInNodeSensorMap(qint32 ID,QByteArray data);
    //将值value插入列field（数据表格rxxxxxxx）
    void insertIntoRData(const QString & Seq,const QString & NodeMacAddress,
          const QString & SensorID,const QString & SensorData,const QString & DataTime);
    /*解析数据，将结果写入数据库。如果isEvent为true，表示是事件型传感器数据；
    否则为普通传感器数据。      */
    void statistic(QByteArray packet,QHostAddress srcAddress, quint16 srcPort, bool isEvent);

    QString dateTime; //最新的一张rxxx表的建立时间
   // quint16 packetLen;  //数据包长度（bit数除以4）
    DatabaseOperation *dbo;
    QMap <qint32,QByteArray> *mapIDInNodeSensorMap_Event; //记录各个传感器的最新Event数据

    QMap <qint16,QByteArray> *mapRefSensorIDVirtualSensorName;

};

#endif // SENSORDATAPROCESS_H
